
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Db4objects;
namespace NCS_CS
{
	public partial class FormShixu
	{
		//Public Sub list1Additem(ByRef i As int, ByRef b As Boolean)
		//    Dim at As int
		//    Dim find As Boolean
		//    at = inArrNew(CInt[i], vlV, nvlv, find)
		//    If find Then
		//        If b Then
		//            List1.Items.Insert(i, vlvName[at] + "on")
		//        Else
		//            List1.Items.Insert(i, vlvName[at] + "off")
		//        End If
		//    Else
		//        If b Then
		//            List1.Items.Insert(i, CStr[i] + "on")
		//        Else
		//            List1.Items.Insert(i, CStr[i] + "off")
		//        End If
		//    End If

		//End Sub

		private void List1_SelectedIndexChanged_1(System.Object sender, System.EventArgs e)
		{
			int i = 0;
			bool b = false;

			i = List1.SelectedIndex;
			if (i == -1)
				return;
			b = MyZed1.getlinevisible(i);
			if (b) {
				MyZed1.setlinevisible(i, false);
				List1.Items.RemoveAt(i);
				List1.Items.Insert(i, ModMain.vlvName[i] + "off");
			} else {
				MyZed1.setlinevisible(i, true);
				List1.Items.RemoveAt(i);
				List1.Items.Insert(i, ModMain.vlvName[i] + "on");
			}
			MyZed1.draw();
		}
		public void setvlv()
		{
			try {
				int i = 0;
				List1.Items.Clear();
				//Dim i As Integer
				for (i = 0; i <= ModMain.nvlv - 1; i++) {
					List1.Items.Insert(i, ModMain.vlvName[i] + "on");
				}
				return;
			} catch (System.Exception e) {
				modLog.savelogmsg(e.ToString()); 
			}
		}
        public int getshixuid(Db4objects.Db4o.IObjectContainer db)
		{
            Db4objects.Db4o.Query.IQuery query = db.Query();
			query.Constrain(typeof(ShixuId));
            Db4objects.Db4o.IObjectSet o = null;
			o = query.Execute();
			ShixuId m = null;
			if (o.Count > 0) {
				m = (ShixuId )o[0];
			} else {
				m = null;
			}
			if ((m != null)) {
				return m.id;
			} else {
				return 0;
			}
		}
		private void FormShixu_Load(object sender, System.EventArgs e)
		{
			setvlv();
			Db4objects.Db4o.IObjectContainer db = null;
			
			db = Db4objects.Db4o.Db4oFactory.OpenFile(modLog.initpath + "\\shixu.data");
			Db4objects.Db4o.Query.IQuery query = db.Query();
			query.Constrain(typeof(ShiXu));
			int id = 0;
			id = getshixuid(db);
			query.Descend("id").Constrain(id);
			Db4objects.Db4o.IObjectSet o = null;
			o = query.Execute();
			ShiXu m = null;
			if (o.Count > 0) {
				m = (ShiXu)o[0];
				m.tocurve(ref this.MyZed1);

			}
			db.Close();
		}
		public FormShixu()
		{
			Load += FormShixu_Load;
			InitializeComponent();
		}
	}
}
